<template>
  <Modal
    title="添加"
    :value="value"
    :mask-closable="true"
    :footer-hide="true"
    @input="$emit('input', $event)"
  >
    <Form
      ref="formTybkStaff"
      :model="formTybkStaff"
      :rules="ruleValidate"
      label-position="right"
      :label-width="80"
    >

      <FormItem label="员工姓名" prop="staff_name">
        <Input type="text" v-model="formTybkStaff.staff_name" placeholder="员工姓名"/>
      </FormItem>
      <FormItem label="公司名称" prop="corporate_name">
        <Input type="text" v-model="formTybkStaff.corporate_name" placeholder="公司名称"/>
      </FormItem>
      <FormItem label="办理资质名称" prop="staff_qualification_name">
        <Input type="text" v-model="formTybkStaff.staff_qualification_name" placeholder="办理资质名称"/>
      </FormItem>
      <FormItem label="合同签订日期" prop="staff_date_signing">
        <DatePicker type="date" v-model="formTybkStaff.staff_date_signing" style="width: 200px"></DatePicker>
      </FormItem>
      <FormItem label="合同金额" prop="staff_contract_amount">
        <Input type="text" v-model="formTybkStaff.staff_contract_amount" placeholder="合同金额"/>
      </FormItem>
      <FormItem label="开票金额" prop="staff_Invoice_amount">
        <Input type="text" v-model="formTybkStaff.staff_Invoice_amount" placeholder="开票金额"/>
      </FormItem>
      <FormItem label="利润" prop="staff_profit">
        <Input type="text" v-model="formTybkStaff.staff_profit" placeholder="利润"/>
      </FormItem>
      <FormItem label="业务提成" prop="staff_commission">
        <Input type="text" v-model="formTybkStaff.staff_commission" placeholder="业务提成"/>
      </FormItem>

      <FormItem>
        <Button type="primary" @click="handleSubmit('formTybkStaff')">提交</Button>
        <Button @click="handleReset('formTybkStaff')" style="margin-left: 8px">重置</Button>
      </FormItem>
    </Form>
  </Modal>
</template>
<script>
import { save } from '@/api/staff'
import { createModelObj } from '@/libs/util'

export default {
  name: 'Add',
  props: {
    value: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      formTybkStaff: {

        id: ''
        ,
        staff_name: ''
        ,
        corporate_name: ''
        ,
        staff_qualification_name: ''
        ,
        staff_date_signing: ''
        ,
        staff_contract_amount: ''
        ,
        staff_Invoice_amount: ''
        ,
        staff_profit: ''
        ,
        staff_commission: ''
        ,
        deleted: '0'
        ,
        create_time: ''
        ,
        modification_time: ''
        ,
        deletion_time: ''
      },
      ruleValidate: {

        id: [
          { required: true, message: '该值不能为空', trigger: 'blur' },
          { type: 'string', max: 32, message: '长度最长为32', trigger: 'blur' }
        ]
        ,
        staff_name: [
          { required: true, message: '该值不能为空', trigger: 'blur' },
          { type: 'string', max: 255, message: '长度最长为255', trigger: 'blur' }
        ]
        ,
        corporate_name: [
          { required: true, message: '该值不能为空', trigger: 'blur' },
          { type: 'string', max: 50, message: '长度最长为50', trigger: 'blur' }
        ]
        ,
        staff_qualification_name: [
          { required: true, message: '该值不能为空', trigger: 'blur' },
          { type: 'string', max: 255, message: '长度最长为255', trigger: 'blur' }
        ]
        ,

        staff_contract_amount: [
          { required: true, message: '该值不能为空', trigger: 'blur' },
          { type: 'string', max: 10, message: '长度最长为10', trigger: 'blur' }
        ]
        ,
        staff_Invoice_amount: [
          { required: true, message: '该值不能为空', trigger: 'blur' },
          { type: 'string', max: 10, message: '长度最长为10', trigger: 'blur' }
        ]
        ,
        staff_profit: [
          { required: true, message: '该值不能为空', trigger: 'blur' },
          { type: 'string', max: 10, message: '长度最长为10', trigger: 'blur' }
        ]
        ,
        staff_commission: [
          { required: true, message: '该值不能为空', trigger: 'blur' },
          { type: 'string', max: 10, message: '长度最长为10', trigger: 'blur' }
        ]
        ,
      }
    }
  },
  methods: {
    handleSubmit (name) {
      this.$refs[name].validate(valid => {
        if (valid) {
          save(Object.assign({}, createModelObj(this.formTybkStaff, 'tybkStaff'))).then(
            res => {
              if (res) {
                this.$emit('addRow', res.row)
                this.$emit('input', false)
                this.handleReset(name)
              }
            }
          )
        } else {
          this.$Message.error('验证失败!')
        }
      })
    },
    handleReset (name) {
      this.$refs[name].resetFields()
    }
  }
}
</script>
